<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	Date date = new Date();
	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
	String dateString = formatter.format(date);
	request.setAttribute("dateString", dateString);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 								
	<head> 		
	    <base target="_self">					
		<%@ include file="../jslib/jquerylib.jsp" %>
		<title>样品归还页面</title>
		<base target="_self"/>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
        <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
        <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
        <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
	       <!-- 删除结果信息返回 -->
	    	<c:if test="${requestScope.message!=null}">
				<script type="text/javascript">
	  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
	  	 		     window.close();
	  			</script>
	        </c:if>
	 
	<script type="text/javascript">
	$(document).ready(function(){
	                var lastrow;
	                var lastcell;
					$("#gridTable").jqGrid({
						url:'<%=request.getContextPath() %>/codeReviewActionNew!querySampleDetailBytaskId.action?flag=3&taskId=<%=request.getParameter("ids")%>&sampleIds=<%=request.getParameter("sampleIds")%>',
						datatype: "json",
						height: 450,
						width: 710, 
						autowidth: true, 
						colNames:['ID','样品名称','样品编号','归还时间','归还数量','操作人','领用人','备注'],
						colModel:[
								{name:'ID',index:'ID', width:100,key:true,hidden:true,sorttype:"int"} ,
								{name:'T_SAMPLENAME',index:'T_SAMPLENAME', width:100},
								{name:'T_SAMPLENO',index:'T_SAMPLENO', width:170},
								{name:'T_GUIHUANTIME',index:'T_GUIHUANTIME', width:80,hidden:false,hidedlg:false,formatter: function(cellvalue, options, rowObject) {
						          return '${dateString}'}},
								{name:'T_GUIHUANNUM',index:'T_GUIHUANNUM', width:100,editable:true, edittype:"text", editrules:{number: true}},
								{name:'T_GUIHUANREN',index:'T_GUIHUANREN', width:100,hidden:false,hidedlg:false,formatter: function(cellvalue, options, rowObject) {
						          return '${sessionScope.username}'}},
						        {name:'T_LINGYONGREN',index:'T_LINGYONGREN', width:180,editable: true,edittype:"text"},
								{name:'T_GUIHUANREMARK',index:'T_GUIHUANREMARK', width:180,editable: true,edittype:"text"}
						], 
						shrinkToFit:false,
						sortname:'ID',
						sortorder:'asc',
						viewrecords:true,
						multiselect: false, // 是否显示复选框
						multiboxonly : true, 
						//gridview: true,  //提升速度
						rownumbers: true,//显示行号
						cellEdit: true,
						forceFit : true,
						cellsubmit: "clientArray",
						rownumWidth: 30, //行号的宽度
						rowNum:15,
						onSelectRow: function(id){  
			                 $("#gridTable").jqGrid("saveCell",lastrow,lastcell);
			            },  
			            beforeEditCell:function(rowid,cellname,v,iRow,iCol){
						   lastrow = iRow;
						   lastcell = iCol;
						},
						rowList:[15,20,50,200,500],
						toolbar: [false,"top"],
						jsonReader: {
							root:"rows",		// 数据行（默认为：rows）
							page: "page",  	// 当前页
							total: "total",  // 总页数
							records: "records",  // 总记录数
							repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
						},
						prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
						pager:"#gridPager",
						caption: "样品归还"
			});
			
			 //确定按钮
		     $("#entry").click(function(){
		        var msg ="";
		        var rowid= $("#gridTable").jqGrid('getDataIDs')+"";
		        var allIds = rowid.split(",");
		        for(var i=0;i<allIds.length;i++){
		            $("#gridTable").jqGrid("saveCell",lastrow,lastcell);
		            var row = $("#gridTable").jqGrid('getRowData', allIds[i]);
		            if(msg!=''){
		               msg = msg +"&@&";
		            }
		            msg = msg +row.ID+"#@#"+row.T_GUIHUANNUM+"#@#"+row.T_LINGYONGREN+"#@#"+row.T_GUIHUANREMARK;
		        }
		        
		        var params = {
		                      "msg":encodeURIComponent(msg)
		                    };
		        var actionUrl = "<%=request.getContextPath() %>/codeReviewActionNew!saveReturnSample.action";  
		             $.ajax({  
		                 url : actionUrl,  
		                 type : "post", 
		                 async: false,//取消异步提交
		                 data : params,  
		                 dataType : "json",  
		                 cache : false,  
		             error : function(textStatus, errorThrown) {  
		                 alert("系统ajax交互错误: " + textStatus.value);  
		             },  
		             success : function(data, textStatus) {
		                if(data.result=='true'){
		                   alert("样品归还成功!");
		                   window.close();
		                }
		                else {
		                  alert("样品归还失败,请重试!");
		                }
		             }  
		         });
				
			});
				
		      /**
		     * 取消
		     */
		    $("#center").click(function(){
		        window.close();
		    });
	  }); 
	
	
	</script>	
	</head>
	<body>
	<form action="" method="post" id="form1">
	      <table style="width: 100%;" class="tableCont">
	      <input type="hidden" id="id1" name="id1" vlaue=""/>
				<tr>
					<td colspan="4">
						<table id="gridTable"></table>
						<div id="gridPager"></div>
					</td>
				</tr>
			</table>
			<table style="width: 100%;">
			   <tr>
			   <td colspan="4" style="text-align: center; height: 20px; font-size: 15px; font-weight: bold;">
		        <button id="entry"  class="button_b">确&nbsp;定</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		        <button id="center" class="button_b" >取&nbsp;消</button>
		       </td>
		      </tr>
			</table>
	</form>
	</body>
</html>
